package com.sname.demoribbon;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

// 允许断路器
@EnableEurekaClient
@SpringBootApplication
@EnableCircuitBreaker

/**
 * @Author 宋贤坤
 * Date & Time  2018/11/15 17:29
 * Description  Ribbon
 */

public class DemoRibbonApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoRibbonApplication.class, args);
    }

    @Bean
    public IRule ribbonRule() {
        return new RandomRule();
    }

    @Bean
    @LoadBalanced
    // 这个注解里面就是各种负载均衡的算法
    /** 声明负载均衡的请求器 */
    RestTemplate restTemplate() {
        // 此时就不是面向ip调用
        return new RestTemplate();
        // 而是面向服务调用
    }
}
